package com.margo.project.security.config;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

/**
 * Spring security登录成功处理类,返回jwt
 * @author fangxingbang
 *
 */
@Component
public class MargoAuthenticationException implements AuthenticationEntryPoint{
	Logger logger=LoggerFactory.getLogger(this.getClass());
	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException authException) throws IOException, ServletException {
		logger.info("AuthenticationEntryPoint检测到异常:"+authException.getMessage());
		response.setStatus(200);
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
        PrintWriter printWriter = response.getWriter();
        response.getWriter().write("AuthenticationEntryPoint检测到异常:"+authException);
        printWriter.flush();
		
	}

}
